package com.lanbu.system.service.impl;

import com.lanbu.system.domain.mongo.MongoOpenApis;
import com.lanbu.system.mapper.MongoOpenApisRepository;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MongoOpenApisService {

    @Autowired
    private MongoOpenApisRepository apiKeyRepository;

    public MongoOpenApis saveApiKey(MongoOpenApis openApis) {
        return apiKeyRepository.save(openApis);
    }

    public void deleteApiKey(String id) {
        apiKeyRepository.deleteById(id);
    }

    public MongoOpenApis findApiKeyById(String id) {
        return apiKeyRepository.findById(id).orElse(null);
    }

    public List<MongoOpenApis> findByTmbId(ObjectId tmbId) {
        return apiKeyRepository.findByTmbId(tmbId);
    }

    public MongoOpenApis findOpenApisByApiKey(String apiKey) {
        MongoOpenApis byApiKey = apiKeyRepository.findByApiKey(apiKey);
        return byApiKey;
    }

    public List<MongoOpenApis> findAllApiKeys() {
        return apiKeyRepository.findAll();
    }
    public   MongoOpenApis findByAppId(String name){
        return apiKeyRepository.findByAppId(name);
    }
}
